package com.woniu.project.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.project.core.domain.ProductEntityAssess;
import com.woniu.project.dao.ProductEntityAssessMapper;
import com.woniu.project.dto.assessdto.AssessDto;
import com.woniu.project.params.assessparams.AssessConditionParams;
import com.woniu.project.params.assessparams.AssessParams;
import com.woniu.project.service.IProductEntityAssessService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.project.service.IProductEntityService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author WHF
 * @since 2020-10-13
 */
@Service
public class ProductEntityAssessServiceImpl extends ServiceImpl<ProductEntityAssessMapper, ProductEntityAssess> implements IProductEntityAssessService {

    @Autowired
    private ProductEntityAssessMapper productEntityAssessMapper;
    @Autowired
    private IProductEntityService productEntityService;

    @Override
    public IPage<AssessDto> selectAssessList(AssessConditionParams assessConditionParams) {
        Page<AssessDto> page=new Page<>(assessConditionParams.getPageIndex(),assessConditionParams.getPageNumber());
        IPage<AssessDto> assessDtoIPage=productEntityAssessMapper.selectAssessList(page,assessConditionParams.getProductEntityId());
        return assessDtoIPage;
    }

    @Override
    public void deleteAssess(Integer productEntityId) {
        productEntityAssessMapper.deleteAssess(productEntityId);
    }

    @Override
    public void insertAssess(AssessParams assessParams) {
        ProductEntityAssess productEntityAssess=new ProductEntityAssess();
        BeanUtils.copyProperties(assessParams,productEntityAssess);
        productEntityAssess.setProductEntityAssessTime(new Date());
        save(productEntityAssess);
        productEntityService.updateAssess(assessParams.getProductEntityId(),assessParams.getAssessManId());
    }
}
